package com.tools.s7.delegate;

import android.content.Context;
import android.content.res.Resources;
import android.os.Bundle;
import android.util.SparseArray;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;


public abstract class BaseFDelegate implements FDelegate {

    protected String LOG_TAG = this.getClass().getSimpleName() + ":mai";

    protected final SparseArray<View> mViews = new SparseArray<>();

    private View rootView;

    public abstract int getLayoutId();

    protected Context mContext;

    public Resources getResources(){
        return mContext.getResources();
    }

    public Context getContext(){
        return mContext;
    }

    @Override
    public void onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        mContext = inflater.getContext();
        rootView = inflater.inflate(getLayoutId(), container, false);
    }

    @Override
    public int getOptionsMenuId() {
        return 0;
    }

    @Override
    public View getRootView() {
        return rootView;
    }

    @Override
    public void initWidget() {

    }

    public <T extends View> T findViewById(int id) {
        T view = (T) mViews.get(id);
        if (view == null) {
            view = rootView.findViewById(id);
            mViews.put(id, view);
        }
        return view;
    }

}
